limsEquipScrap.auditPage = {

    getGridParam: function () {
        var _this = this
        return {
            type: 'grid',
            id: 'lims-equip-scrap-audit-list-grid',
            url: limsEquipScrap.baseUrl + '/queries/tasks',
            columns: limsEquipScrap.getAuditListColumns(),
            onCellClick: function (field, row) {
                field === 'equipCode' && _this.loadDetailPage(row.id)
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.PASS',
                icon: 'pass',
                onClick: function () {
                    _this.pass()
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.REJECT',
                icon: 'reject',
                onClick: function () {
                    _this.reject()
                }
            }]
        }
    },

    pass: function () {
        var grid = Gikam.getComp('lims-equip-scrap-audit-list-grid')
        Gikam.create('workflow').pass({
            data: grid.getSelections(),
            pageObject: limsEquipScrap,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            grid.refresh()
        })
    },

    reject: function () {
        var grid = Gikam.getComp('lims-equip-scrap-audit-list-grid')
        Gikam.create('workflow').reject({
            data: grid.getSelections(),
            pageObject: limsEquipScrap,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            grid.refresh()
        })
    },

    loadDetailPage: function (id) {
        workspace.window.load(limsEquipScrap.baseUrl + '/page/detail' + Gikam.param({
            id: id,
            step: 'audit'
        }))
    },

    create: function () {
        var _this = this
        Gikam.create('layout', {
            id: 'lims-equip-scrap-audit-list-layout',
            renderTo: workspace.window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        })
    },

    init: function (param) {
        this.param = param
        this.create()
    }
}
